package com.commons.exception;

import com.commons.enums.ResponseCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author mis_wu
 * @date 2021/12/5 13:18
 * 全局异常处理
 */
@ControllerAdvice
@SuppressWarnings("all")
public class GlobalExceptionHandler {

    //自定义控制器异常方法,可处理控制器中的所有异常
    @ExceptionHandler
    @ResponseBody
    public Map exceptionHandler(Exception e){
        HashMap map = new HashMap();
        map.put("status", ResponseCodeEnum.FAIL.getCode());
        map.put("info", ResponseCodeEnum.FAIL.getMsg());
        map.put("msg",e.getMessage());
        return map;
    }
}
